//
//  InfomationCell.m
//  Shengzhuli
//
//  Created by FXGuo on 17/3/19.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "InfomationCell.h"
#import <UIImageView+WebCache.h>
#import "NSDate+Extension.h"

@interface InfomationCell()
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLab;



@end

@implementation InfomationCell

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setActivityModel:(ActivityModel *)activityModel
{
    _activityModel = activityModel;
    self.titleLab.text = activityModel.title;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:activityModel.activityPictureUrl] placeholderImage:GetImage(@"default_goods_image")];
    self.timeLab.text = [NSString stringWithFormat:@"活动时间：%@",[NSDate spToDateString:activityModel.startDate]];
}
- (void)setInfoModel:(InfomationModel *)infoModel
{
    _infoModel = infoModel;
    self.titleLab.text = infoModel.title;
    self.subTitleLab.text = infoModel.subtitle;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:infoModel.avatarUrl] placeholderImage:GetImage(@"default_goods_image")];
    NSInteger count = [NSString stringWithFormat:@"%zd",infoModel.viewCount].length;
    NSString *str = [NSString stringWithFormat:@"%zd人已浏览",infoModel.viewCount];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#3285ff"]} range:NSMakeRange(0, count)];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#888888"]} range:NSMakeRange(count, str.length-count)];
    self.timeLab.attributedText = attrStr;
}
- (void)setOldModel:(OldActivityModel *)oldModel
{
    _oldModel = oldModel;
    self.titleLab.text = oldModel.title;
    self.subTitleLab.text = oldModel.subtitle;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:oldModel.avatarUrl] placeholderImage:GetImage(@"default_goods_image")];
    NSInteger count = [NSString stringWithFormat:@"%zd",oldModel.viewCount].length;
    NSString *str = [NSString stringWithFormat:@"%zd人已浏览",oldModel.viewCount];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#3285ff"]} range:NSMakeRange(0, count)];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#888888"]} range:NSMakeRange(count, str.length-count)];
    self.timeLab.attributedText = attrStr;
}

@end
